﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace WpfControlDemo.依赖属性
{
    /// <summary>
    /// 1. 附加依赖属性需要继承自DependencyObject
    /// </summary>
    public class RemarkHelper : DependencyObject
    {
        /// <summary>
        /// 2. 声明附加属性
        /// </summary>
        public static readonly DependencyProperty DescriptionProperty;
        static RemarkHelper()
        {
            // 3. 注册附加属性
            // 参数1：设置附加属性名称 参数2：设置附加属性值类型 参数3：设置附加属性所属类型 参数4：设置附加属性默认值
            DescriptionProperty = DependencyProperty.RegisterAttached("Description", typeof(string), typeof(RemarkHelper), new PropertyMetadata(string.Empty));
        }

        // 4. 附加属性包装，提供属性读写操作
        /// <summary>
        /// 读取值
        /// </summary>
        /// <param name="dpa"></param>
        /// <returns></returns>
        public static string GetDescription(DependencyObject dpa)
        {
            return (string)dpa.GetValue(DescriptionProperty);
        }
        /// <summary>
        /// 设置值
        /// </summary>
        /// <param name="dpa"></param>
        /// <param name="value"></param>
        public static void SetDescription(DependencyObject dpa, string value)
        {
            dpa.SetValue(DescriptionProperty, value);
        }
    }
}
